pub mod compute;
pub mod optimize;

use std::sync::Arc;
use tokio::sync::mpsc;
use arrow::record_batch::RecordBatch;
use crate::bridge::r#async::{Task, TaskQueue};

pub struct ComputeEngine {
    task_queue: Arc<TaskQueue>,
}

impl ComputeEngine {
    pub fn new(task_queue: Arc<TaskQueue>) -> Self {
        Self { task_queue }
    }
    
    pub async fn submit_task<F, Fut>(&self, id: u64, f: F) -> Result<(), Box<dyn std::error::Error + Send>>
    where
        F: FnOnce() -> Fut + Send + 'static,
        Fut: std::future::Future<Output = Result<(), Box<dyn std::error::Error + Send>>> + Send + 'static,
    {
        let future = Box::pin(async move {
            f().await
        });
        
        let task = Task::new(id, future);
        self.task_queue.push(task).await?;
        
        Ok(())
    }
}